package com.taotao.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.taotao.common.pojo.EUDataGridResult;
import com.taotao.common.pojo.TaotaoResult;
import com.taotao.pojo.TbItemParam;
import com.taotao.service.IItemParamService;

@Controller
@RequestMapping(value = "/item/param")
public class ItemParamController {
	@Autowired
	private IItemParamService itemParamService;

	/**
	 * 分页查询商品规格信息
	 * 
	 * @param page
	 * @param rows
	 * @return
	 */
	// http://localhost:8080/item/param/list?page=1&rows=30
	@RequestMapping(value = "/list")
	@ResponseBody
	public EUDataGridResult getItemParamList(Integer page, Integer rows) {
		return this.itemParamService.getItemParemList(page, rows);
	}

	/**
	 * 通过商品类目id查询商品规格是否存在
	 * 
	 * @param itemcatid
	 * @return
	 */
	// http://localhost:8080/item/param/query/itemcatid/298
	@RequestMapping(value = "/query/itemcatid/{itemcatid}")
	@ResponseBody
	public TaotaoResult getItemParemByItemCatId(@PathVariable Long itemcatid) {
		return this.itemParamService.getItemParemByItemCatId(itemcatid);
	}

	/**
	 * 保存商品规格信息
	 * 
	 * @param itemcatid
	 * @param itemParam
	 * @return
	 */
	// http://localhost:8080/item/param/save/166
	@RequestMapping(value = "/save/{itemcatid}")
	@ResponseBody
	public TaotaoResult getItemParemByItemCatId(@PathVariable Long itemcatid,
			TbItemParam itemParam) {
		itemParam.setItemCatId(itemcatid);
		return this.itemParamService.saveItemParem(itemParam);
	}
}
